package stack.era.presentation.main_menu;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.FileInputStream;
import java.io.IOException;

import javax.swing.JLabel;

import stack.era.constants.ImageAttributes.ImageCacheName;
import stack.era.domain.DomainController;
import stack.era.presentation.ERAFrameCardPanel;
import stack.era.presentation.images.ImageCache;

public class MainMenuPanel extends ERAFrameCardPanel {

	private static final long serialVersionUID = 1297417376849049276L;

	private MainMenuButton newGameButton;
	private MainMenuButton exitGameButton;
	private MainMenuButton continueGameButton;

	public MainMenuPanel() {
		super();
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.gridheight = 1;
		c.gridwidth = 1;
		c.insets = new Insets(5, 5, 5, 5);
		c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.ipady = 30;
		c.ipadx = 60;
		c.gridx = 0;

		Font f = null;
		try {
			f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(
					"font/Abbeyline.ttf"));
		} catch (FontFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		JLabel title = new JLabel("Era");
		title.setHorizontalAlignment(JLabel.CENTER);
		title.setFont(f.deriveFont(Font.TRUETYPE_FONT, 50));
		c.gridy = 0;
		c.ipady = 0;
		c.fill = GridBagConstraints.HORIZONTAL;
		this.add(title, c);

		c.fill = GridBagConstraints.BOTH;
		c.ipady = 30;

		newGameButton = new MainMenuButton("New Game");
		newGameButton.addActionListener(new NewGameControl());
		c.gridy = 1;
		this.add(newGameButton, c);

		continueGameButton = new MainMenuButton("Continue Game");
		c.gridy = 2;
		this.add(continueGameButton, c);

		exitGameButton = new MainMenuButton("Exit Game");
		exitGameButton.addActionListener(new ExitGameControl());
		c.gridy = 3;
		this.add(exitGameButton, c);

		JLabel subtitle = new JLabel("Discovery");
		subtitle.setHorizontalAlignment(JLabel.CENTER);
		subtitle.setFont(f.deriveFont(Font.TRUETYPE_FONT, 40));
		subtitle.setForeground(Color.WHITE);
		c.gridy = 4;
		c.ipady = 0;
		c.fill = GridBagConstraints.HORIZONTAL;
		this.add(subtitle, c);
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.drawImage(ImageCache.getInstance().getImage(
				ImageCacheName.MOUNTAIN_BACKGROUND), 0, 0, this.getWidth(),
				this.getHeight(), null, this);
	}

	@Override
	public void populate() {
		continueGameButton.setEnabled(DomainController.getInstance()
				.loadedGameFound());
	}

	@Override
	public void doneWaiting() {
		// TODO Auto-generated method stub
		
	}

}
